package net.haiyue.api.service;

import net.haiyue.api.entity.SelectInfo;
import net.haiyue.api.entity.User;
import net.haiyue.api.repository.UserRepository;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.Arrays;
import java.util.List;

@Service
public class UserService {
    @Resource
    private UserRepository _repository;

    public List<User> All() {
        return _repository.findAll();
    }
    public User CheckUser(String email,String pwd){
        User user=_repository.findUserByEmail(email);
        if (user!=null &&  user.getPwd().equals(pwd)){
            return user;
        }
        return null;
    }
    public User Add(User user){
        User exist=_repository.findUserByEmail(user.getEmail());
        if (exist!=null)return  null;
        return _repository.save(user);
    }
    public List<SelectInfo> selectUsers(){
        return _repository.selectUsers();
    }

    public List<User> findAllById(Integer[] ids){
        return _repository.findAllById(Arrays.asList(ids));
    }

    public void changeAdmin(Integer id,boolean value){
          _repository.updateAdmin(id,value);
    }
}
